package com.heima.Work;

public class Work2 implements Runnable {
    private int lipin = 100;

    @Override
    public void run() {
        while (true) {
            synchronized (Work2.class) {
                if (lipin <= 10) {
                    System.out.println("礼品少于10不发放");
                    break;
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    lipin--;
                    System.out.println(Thread.currentThread().getName() + "在发礼品。还剩下" + lipin + "个礼品");
                }
            }
        }
    }
}
